package com.CST.controller.cb;


import com.CST.common.api.Response;
import com.CST.common.api.ResultObject;
import com.CST.entity.cb.CusDutyfactor;
import com.CST.entity.cb.selectInfo;
import com.CST.service.cb.ICusDutyfactorService;
import com.CST.util.PageHelperTool;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;

import java.util.*;

import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xnd
 * 多角色工作系数增删改查
 * @since 2021-12-22
 */
@Api(tags = {"多角色工作系数"})
@RestController
@RequestMapping("/cusDutyfactor")

public class CusDutyfactorController {

    @Autowired
    private ICusDutyfactorService targetService;


    @PostMapping("/addRoleworkfactor")
    @ApiOperation("新增员工工作系数")
    public ResultObject addRoleworkfactor(@RequestBody CusDutyfactor entity) {
        Response result = targetService.addRoleworkfactor(entity);
        return ResultObject.resultReturn(result);
    }


    @PostMapping("/selectworkfactor")
    @ApiOperation("查看工作系数")
    public ResultObject selectworkfactor(@RequestBody CusDutyfactor entity) {
        List<CusDutyfactor> result = targetService.selectworkfactor(entity);
        if (CollectionUtils.isEmpty(result)) {
            return ResultObject.successReturn(new ArrayList<CusDutyfactor>());
        }
        PageInfo<CusDutyfactor> resultList = PageHelperTool.excutePageInfo(result, entity.getPageIndex(), entity.getPageSize());
        return ResultObject.successReturn(resultList);
    }

    @PostMapping("/getYearMonth")
    @ApiOperation("获取年月下拉数据")
    public ResultObject getYearMonth() {
        List<selectInfo> result = targetService.getYearMonth();
        if (CollectionUtils.isEmpty(result)) {
            return ResultObject.successReturn(new ArrayList<>());
        }
        return ResultObject.successReturn(result);
    }


    @DeleteMapping("/Deleteinformation")
    @ApiOperation("删除")
    public ResultObject Deleteinformation(@RequestBody List<Integer> ids) {
        if (ids == null || ids.stream().count() == 0) {
            return ResultObject.errorReturn("请选择要删除的记录");
        }
        Response result = targetService.Deleteinformation(ids);
        return ResultObject.resultReturn(result);
    }

    @PostMapping("/modifyworkfactor")
    @ApiOperation("修改")
    public ResultObject modifyworkfactor(@RequestBody CusDutyfactor entity) {
        if (entity.getId() == null || entity.getId() == 0) {
            return ResultObject.errorReturn("未获取到记录ID!");
        }
        Response result = targetService.modifyworkfactor(entity);
        return ResultObject.resultReturn(result);
    }


    @GetMapping("/getbyid")
    @ApiOperation("详情信息")
    public ResultObject getbyid(@RequestParam int id) {
          CusDutyfactor info =targetService.getById(id);
          return ResultObject.successReturn(info);
    }

    @PostMapping("/insertRoleworkfactor")
    @ApiOperation("继承添加")
    public ResultObject insertRoleworkfactor(@RequestBody CusDutyfactor entity) {
        Response result = targetService.insertRoleworkfactor(entity);
        return ResultObject.resultReturn(result);
    }

}

